const seatsModel = require("../models/seatsModel");

module.exports = {
    //查询
    async Allseats() {
        return await seatsModel.find().exec()
    },
    //创建选座位置
    async seatsData({row,col,displayName,theaterId}) {
        return await seatsModel.create({
            row,col,displayName,theaterId
        })
    },
     //查找所有的选座详细信息
     async showSeatsData() {
        return await seatsModel.find().exec()
    },
     //查找行列
     async queryToRepeat({row,col}) {
        return await seatsModel.findOne({row,col}).exec()
    },
    // 查看完整信息
    async completeInformation(seatsId) {
        return await seatsModel.findById(seatsId).exec()
    },
     //删除选座
     async deleteSeats(seatsid) {
        return await seatsModel.deleteOne({
            '_id':seatsid
        }).exec()
    },
    //修改选座
    async modifySeats({'_id':seatsId},{row,col,displayName,theaterId}) {
        return await seatsModel.updateOne({'_id':seatsId}, {row,col,displayName,theaterId}).exec()
    },
    //分页
    // currentPage:当页页数
    // pageSize： 每页显示的条数 
    async accessToPag({
        currentpage,
        pagesize
    }) {
        return await seatsModel.find()
            .skip((currentpage - 1) * pagesize)
            .limit(pagesize)
            .sort({
                '_id': -1
            })
            .exec()
    },
    //数据的总条数
    async getsNumber() {
        return seatsModel.countDocuments().exec()
    },
}